/*
 DNN Content Builder - sourceforge.net/projects/dnncb
 Copyright (c) 2004-2008
 by Emerson Lopes (emersonlopes@gmail.com)

 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
 to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions 
 of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 DEALINGS IN THE SOFTWARE.
*/

using System;
using System.Collections;
using System.Data;

namespace DNNContentBuilder 
{
	[Serializable]
	public class TemplateDefinitionInfo 
	{
        
		// Entity member variables for database table epTemplateDefinition
        
		private Int32 mTemplateDefinitionId;
		private string mTemplateName;
		private string mBody;
		private Int32 mFormDefinitionId;
        
		// Calculated Expression member variables for database table epTemplateDefinition
        
        
		// Entity properties for database table epTemplateDefinition
        
		public Int32 TemplateDefinitionId 
		{
			get { return mTemplateDefinitionId; }
			set { mTemplateDefinitionId = value; }
		}
        
        
		public string Body 
		{
			get { return mBody; }
			set { mBody = value; }
		}
        
		public string TemplateName 
		{
			get { return mTemplateName; }
			set { mTemplateName = value; }
		}
        
		public Int32 FormDefinitionId 
		{
			get { return mFormDefinitionId; }
			set { mFormDefinitionId = value; }
		}
	}
    
	public class TemplateDefinitionController : BaseController
	{
		public TemplateDefinitionController() : base() {}

		public TemplateDefinitionController(ConnectionProvider cp) : base(cp) {}
        
		public Int32 Add(TemplateDefinitionInfo TemplateDefinitionInfo) 
		{
			return (Int32) base.GetDataProvider().TemplateDefinitionAdd(TemplateDefinitionInfo.TemplateName, TemplateDefinitionInfo.Body, TemplateDefinitionInfo.FormDefinitionId);
		}
        
		public void Update(TemplateDefinitionInfo TemplateDefinitionInfo) 
		{
			base.GetDataProvider().TemplateDefinitionUpdate(TemplateDefinitionInfo.TemplateDefinitionId, TemplateDefinitionInfo.TemplateName, TemplateDefinitionInfo.Body, TemplateDefinitionInfo.FormDefinitionId);
		}
        
		public void Delete(Int32 templateDefinitionId) 
		{
			base.GetDataProvider().TemplateDefinitionDelete(templateDefinitionId);
		}
        
		public TemplateDefinitionInfo GetItem(Int32 templateDefinitionId) 
		{
			using (IDataReader idr = base.GetDataProvider().TemplateDefinitionGet(templateDefinitionId))
			{
				TemplateDefinitionInfo infoObject = (TemplateDefinitionInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(TemplateDefinitionInfo));
				return infoObject;
			} 
		}

		public TemplateDefinitionInfo GetItemByName(string templateName) 
		{
			using (IDataReader idr = base.GetDataProvider().TemplateDefinitionGetByName(templateName))
			{
				TemplateDefinitionInfo infoObject = (TemplateDefinitionInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(TemplateDefinitionInfo));
				return infoObject;
			} 
		}

		// Select query methods for database table epTemplateDefinition
        
		public TemplateDefinitionInfo GetTemplateDefinitionFormDefinition(Int32 FormDefinitionId) 
		{
			using (IDataReader idr = base.GetDataProvider().TemplateDefinitionGetByFormId(FormDefinitionId))
			{
				TemplateDefinitionInfo info = (TemplateDefinitionInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(TemplateDefinitionInfo));
				return info;
			} 
		}
        
		// Relation methods for database table epTemplateDefinition
        
		public TemplateDefinitionInfo GetByModuleId(Int32 moduleId) 
		{
			using (IDataReader idr = base.GetDataProvider().TemplateDefinitionByModuleId(moduleId))
			{
				TemplateDefinitionInfo info = (TemplateDefinitionInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(TemplateDefinitionInfo));
				return info;
			} 
		}
	}
}
